package com.collection.linkedlist;

import java.util.LinkedList;

public class CheckElementLinkedListExample {
	public static void main(String[] args) {
		 
	    //create LinkedList object
	    LinkedList lList = new LinkedList();
	   
	    //add elements to LinkedList
	    lList.add("1");
	    lList.add("2");
	    lList.add("3");
	    lList.add("4");
	    lList.add("5");
	   
	    /*
	     * To check if a particular element exists in a LinkedList, use
	     * boolean contains(Object obj) method.
	     *
	     * This method returns true if LinkedList contains a particular element,
	     * false otherwise.
	     */
	   
	     boolean blnElement = lList.contains("4");
	   
	     if(blnElement)
	     {
	       System.out.println("LinkedList contains 4");
	     }
	     else
	     {
	       System.out.println("LinkedList does not contain 4");
	     }
	  }
}
